
package chapter3;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.geom.*;

public class Ex6 extends JApplet {
  public static void main(String s[]) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JApplet applet = new Ex6();
    applet.init();
    frame.getContentPane().add(applet);
    frame.pack();
    frame.setVisible(true);
  }
  
  public void init() {
    JPanel panel = new Ex6Panel();
    getContentPane().add(panel);
  }
}

class Ex6Panel extends JPanel {
  public Ex6Panel() {
    setPreferredSize(new Dimension(400, 400));
    setBackground(Color.white);
  }

  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    int w = getWidth();
    int h = getHeight();
    float r = Math.min(w, h)/2 - 10;
    path.moveTo(r, 0);
    for (int i = 1; i < 5; i++) {
        float x = (float)(r * Math.cos(i*2*Math.PI/5));
        float y = (float)(r * Math.sin(i*2*Math.PI/5));
        path.lineTo(x, y);
    }
    path.closePath();
    Stroke stroke = new BasicStroke(20, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);
    g2.setStroke(stroke);
    g2.translate(w/2, h/2);
    g2.draw(path);

  }
}